package com.cqjtu.email;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

    private EditText mUser;
    private EditText mPass;
    private Button mLogin;
    public static String username;
    public static String password;
    private boolean check;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle data = msg.getData();
             check = data.getBoolean("value");
            if (check) {
                Intent intent = new Intent(MainActivity.this,MyActivity.class);
                startActivity(intent);
            } else {
                Toast.makeText(MainActivity.this, "登录失败！", Toast.LENGTH_SHORT).show();
            }
        }
    };
    Runnable network = new Runnable() {
        @Override
        public void run() {
            boolean b = checkState.Check();
            Message msg = new Message();
            Bundle data = new Bundle();
            data.putBoolean("value", b);
            msg.setData(data);
            handler.sendMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.login);
        initView();

    }

    private void initView() {
        mLogin = (Button) findViewById(R.id.id_btn_login);
        mUser = (EditText) findViewById(R.id.id_user);
        mPass = (EditText) findViewById(R.id.id_pass);

        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                username = mUser.getText().toString();
                password = mPass.getText().toString();

                new Thread(network).start();

            }
        });
    }

}
